<template>
  <div>
    <n-modal
      v-if="props.showModal"
      v-model:show="props.showModal"
      :mask-closable="true"
      @update:show="$emit('CheckShowModal', false)"
    >
      <n-card
        style="width: 600px"
        :title="childName"
        :bordered="false"
        size="huge"
        role="dialog"
        aria-modal="true"
      >
        <template #header-extra>
          <n-button type="error" @click="$emit('CheckShowModal', false)">
            X
          </n-button>
        </template>
        <n-form ref="formRef" :model="model" :rules="rules">
          <n-form-item path="pName" label="商品名称">
            <n-input v-model:value="model.pName" placeholder="请输入商品名称" />
          </n-form-item>
          <n-form-item path="pFalg" label="商品介绍">
            <n-input v-model:value="model.pFalg" placeholder="请输入商品介绍" />
          </n-form-item>
          <n-form-item path="pInfo" label="商品详情">
            <n-input v-model:value="model.pInfo" placeholder="请输入商品详情" />
          </n-form-item>
          <n-form-item path="pPrice" label="商品价格">
            <n-input v-model:value="model.pPrice" placeholder="请输入价格" />
          </n-form-item>
          <UpLoad @filename="filename" @fileself="fileself"></UpLoad>
          <n-row :gutter="[0, 24]">
            <n-col :span="24">
              <div style="display: flex; justify-content: center">
                <n-button round type="primary" @click="UpdateUserFile">
                  添加
                </n-button>
              </div>
            </n-col>
          </n-row>
        </n-form>
      </n-card>
    </n-modal>
    <n-skeleton v-else text :repeat="2" />
    <n-skeleton text style="width: 60%" />
  </div>
</template>

<script lang="ts" setup>
import { defineProps, ref, reactive } from "vue";
import { addChildrenGoods } from "@/api/childrenGoods";
import UpLoad from "@/components/upload/UpLoad.vue";
const formRef = ref();
const emit = defineEmits(["CheckShowModal", "reloadpage"]);
const props = defineProps({
  showModal: {
    type: Boolean,
    default: false,
  },
  userId: {
    type: Number,
    default: "",
  },
  childName: {
    type: String,
    default: "",
  },
});
const childName = ref();
childName.value=`添加${props.childName}子公司商品`
const model = reactive({
  pName: "",
  pFalg: "",
  pPrice: "",
  pInfo: "",
  scId: props.userId,
  file: "",
});
const rules = {
  pName: [
    {
      required: true,
      message: "请输入商品名称",
      trigger: ["input", "blur"],
    },
  ],
  pFalg: [
    {
      required: true,
      message: "请输入商品介绍",
      trigger: ["input", "blur"],
    },
  ],
  pPrice: [
    {
      required: true,
      message: "请输入商品价格",
      trigger: ["input", "blur"],
    },
  ],
  pInfo: [
    {
      required: true,
      message: "请输入商品详情",
      trigger: ["input", "blur"],
    },
  ],
};
const filename = (val: any) => {
  
};
const fileself = (val: any) => {
  model.file = val;
};
const UpdateUserFile = (e: Event) => {
  e.preventDefault();
  formRef.value.validate((err: any) => {
    if (err) {
      console.log(err);
    } else {
      addChildrenGoods(model).then((res: any) => {
        emit("CheckShowModal", false);
        emit("reloadpage");
      });
    }
  });
};
</script>

<style scoped lang="scss"></style>
